package cn.simon.service;

import cn.simon.mapper.SellerMapper;
import cn.simon.model.Seller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

@Service
public class SellerService {
    @Autowired
    private SellerMapper sellerMapper;


    /**
     * 查询所有商家信息
     */
    public List<Seller> findAll() {

        return sellerMapper.selectList(null);
    }

    /**
     * 冻结商家
     */
    public Integer freezeSeller(Integer id) {
        return sellerMapper.updateById(Seller.builder().sellerId(id).sellerState(0).build());
    }

    /**
     * 激活/审批 商家
     */
    public Integer unFreezeSeller(Integer id) {
        return sellerMapper.updateById(Seller.builder().sellerId(id).sellerState(2).build());
    }

    /**
     * 查看需要的审批商家
     */
    public List<Seller> getApproveSeller() {
        QueryWrapper<Seller> wrapper = new QueryWrapper<>();
        wrapper.eq("seller_state", 1);
        return sellerMapper.selectList(wrapper);
    }


    /**
     * 通过卖家ID查找信息
     */
    public Seller findSellerId(Integer id) {
        Wrapper<Seller> sellerWrapper = new QueryWrapper<Seller>().eq("seller_id", id);
        return sellerMapper.selectById(sellerWrapper);
    }

    /**
     * 通过卖家ID修改信息
     */
    public int updateSellerId(Seller seller) {
        return sellerMapper.updateById(seller);
    }

    /**
     * 通过卖家id获取卖家信息
     *
     * @param sellerId
     * @return seller
     * @author Kinfer
     * @date 2022/10/27
     */
    public Seller getSellerById(Integer sellerId) {
        return sellerMapper.selectById(sellerId);
    }
}
